#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
int main()
{
  int pipefd[2] = {0};
  if(pipe(pipefd)!=0)
  {
    perror("pipe error\n");
  }
  pid_t pid = fork();
  if (pid == -1)
  {
    perror("fork error\n");
    return 1;
  }
  if (pid != 0) 
  {
    close(pipefd[0]);
    const char buf[] = "i am father";
    write(pipefd[1],buf, strlen(buf));
    close(pipefd[1]);
  }
  close(pipefd[1]);
  char buf[20] = {0};
  read(pipefd[0], buf, 20);
  printf("%s\n", buf);
  close(pipefd[0]);
  exit(0);
  return 0;
}
